package com.example.smart_city_0829.activity.government;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.smart_city_0829.R;
import com.example.smart_city_0829.base.BaseActivity;
import com.example.smart_city_0829.entity.gov.GovAdvDetail;
import com.example.smart_city_0829.retrofit.NetCallBack;
import com.example.smart_city_0829.utils.Constant;

import retrofit2.Call;
import retrofit2.Response;

public class GovAdvDetailActivity extends BaseActivity {

    private ImageView imageView;
    private TextView title;
    private TextView content;
    private TextView undertake;
    private TextView createTime;
    private TextView state;
    private TextView result;

    private int id;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_gov_adv_detail;
    }

    @Override
    protected void initView() {
        imageView = (ImageView) findViewById(R.id.imageView);
        title = (TextView) findViewById(R.id.title);
        content = (TextView) findViewById(R.id.content);
        undertake = (TextView) findViewById(R.id.undertake);
        createTime = (TextView) findViewById(R.id.createTime);
        state = (TextView) findViewById(R.id.state);
        result = (TextView) findViewById(R.id.result);
    }

    @Override
    protected void initData() {
        id = getIntent().getIntExtra("id", -1);

        api.getAdvDetail(id).enqueue(new NetCallBack<GovAdvDetail>() {
            @Override
            public void onResponse(Call<GovAdvDetail> call, Response<GovAdvDetail> response) {
                if (response.body() == null) return;
                final GovAdvDetail.DataBean data = response.body().getData();
                title.append(data.getTitle());
                content.append(data.getContent());
                undertake.append(data.getUndertaker());
                createTime.append(data.getUndertaker());
                state.append(Integer.parseInt(data.getState()) == 0 ? "等待处理中" : "已处理");

                result.setText(TextUtils.isEmpty(data.getDetailResult())?"暂未查询到结果，请稍后再试...":data.getDetailResult());

                Glide.with(GovAdvDetailActivity.this)
                        .load(Constant.BASE_URL)
                        .into(imageView);
            }
        });
    }

    @Override
    protected void initEvent() {

    }

    @Override
    protected String getActionBarTitle() {
        return "诉求详情";
    }
}